<?php

namespace App\Http\Controllers\api\pay;

use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Cache;
use Yansongda\Pay\Pay;
use Yansongda\Pay\Log;
class PayController extends Controller
{
    protected $config = [
        'app_id' => '2021000121692883',
        'notify_url' => 'http://feng.fengwei.ink/api/fw/notify',
        'return_url' => 'http://feng.fengwei.ink/api/fw/return',
        'ali_public_key' => 'MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAshxJmCh2GYXn4Aw+CXo8PVZGW8hlhXzCdYHfiQIhvhrBj4VVl7rMpt2v8j1u8e03VbHXPQbwaJTReNmecZBh4YGh+CUpzdPgnszqVnRbdSv+JY0QPHudo7Z2+P5s6hdcssQ7qPfVJjVQLHwwWmZcenI6B5TtGL4PotJldGvVYoY63zhg9M11Qw6/fM+6rzIXJ8iBMkB7xeqbav4D2DHjlvtVL/+eLpFixLz6VRNmVmGnoIJyRE9/HE9jve975qMuCrzcSCMNy4mxVLxGnrMAVA4+p+Lxe04tXlQNSuYaCN2oZATH9/wXHPa37E5jBo+OQZfoJ2QbplxLWnzVw2IxnwIDAQAB',
        // 加密方式： **RSA2**
        'private_key' => 'MIIEowIBAAKCAQEAshxJmCh2GYXn4Aw+CXo8PVZGW8hlhXzCdYHfiQIhvhrBj4VVl7rMpt2v8j1u8e03VbHXPQbwaJTReNmecZBh4YGh+CUpzdPgnszqVnRbdSv+JY0QPHudo7Z2+P5s6hdcssQ7qPfVJjVQLHwwWmZcenI6B5TtGL4PotJldGvVYoY63zhg9M11Qw6/fM+6rzIXJ8iBMkB7xeqbav4D2DHjlvtVL/+eLpFixLz6VRNmVmGnoIJyRE9/HE9jve975qMuCrzcSCMNy4mxVLxGnrMAVA4+p+Lxe04tXlQNSuYaCN2oZATH9/wXHPa37E5jBo+OQZfoJ2QbplxLWnzVw2IxnwIDAQABAoIBAHoqnPAZEKiBCILM4uBtT1RjEO9zjO76nActhb3cEHjssUdYFVV1c1ohRMXL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kS2qoNnufps0R9XfYQXgP6BLFcx0k8qQUzHYO/AMd9uC3aRzEYAxhnaozLVh9FR3PMjj1DRi/gZyeeGF9ew4DQ5NksO',
        'http' => [ // optional
            'timeout' => 5.0,
            'connect_timeout' => 5.0,
            // 更多配置项请参考 [Guzzle](https://guzzle-cn.readthedocs.io/zh_CN/latest/request-options.html)
        ],
        'mode' => 'dev', // optional,设置此参数，将进入沙箱模式
    ];
    public function index()
    {
        $order = [
            'out_trade_no' => time(),
            'total_amount' => '1',
            'subject' => 'test subject - 测试',
        ];

        $alipay = Pay::alipay($this->config)->web($order);
        return $alipay;
    }
    public function return()
    {
        return '支付成功';
        // 订单号：$data->out_trade_no
        // 支付宝交易号：$data->trade_no
        // 订单总金额：$data->total_amount
    }

    public function notify(Request $request)
    {
        $alipay = Pay::alipay($this->config);
        $data=$request->all();
        Cache::put('fw',$data);
        try{
            $data = $alipay->verify(); // 是的，验签就这么简单！


        } catch (\Exception $e) {
            \Illuminate\Support\Facades\Log::info($e->getMessage());
        }

        return $alipay->success()->send();// laravel 框架中请直接 `return $alipay->success()`

    }
    public function getCode(){
        $data=Cache::get('fw');
        print_r($data);
    }
}
